package com.moyu.user.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.moyu.common.core.domain.R;
import com.moyu.user.domain.dept.Dept;
import com.moyu.user.service.IDeptService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 赵彦博
 * @Date 2024/11/19 17:35
 */
@RestController
@RequestMapping("depts")
@Tag(name = "部门接口")
public class DeptController {

    @Autowired
    private IDeptService deptService;

    @SaCheckRole("部门管理员")
    @PostMapping("createDept")
    public R<Dept> createDept(@RequestBody Dept dept) {
        return R.ok(deptService.createDept(dept));
    }

    @PostMapping("queryByDeptName")
    public R<Dept> queryByDeptName(@PathVariable String name) {
        return R.ok(deptService.queryByDeptName(name));
    }

    @GetMapping("list")
    public R<List<Dept>> listDept() {
        return R.ok(deptService.list());
    }

    @SaCheckRole("部门管理员")
    @PutMapping("updateDept")
    public R<Dept> updateDept(@RequestBody Dept dept) {
        return R.ok(deptService.update(dept));
    }

    @SaCheckRole("部门管理员")
    @DeleteMapping("{id}")
    public R deleteDept(@PathVariable Long id) {
        deptService.delete(id);
        return R.ok();
    }
}
